<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图文详情页</title>
    <meta content="1280*720" name="page-view-size" http-equiv="">
    <link rel="stylesheet" href="../css/imgText.css">
    <script type="text/javascript" src="../js/yajax.js"></script>
</head>
<body>
<p class="title">标题</p>
<p class="time">时间</p>
<p class="source">来源</p>
<img src="" class="img">
<p class="btn">查看大图</p>
<div class="content">
    <div id="content"></div>
</div>
<!--<div class="setPiece"><img src="../images/imgText/top.png"><img src="../images/imgText/btm.png"><span>翻篇</span></div>-->
<div class="setPage"><img src="../images/imgText/lf.png"><img src="../images/imgText/rt.png"><span>翻页</span></div>
<p class="page">1/1</p>

<script src="../js/S.js"></script>
<script src="../js/common.js"></script>
<script type="text/javascript">
    var clickFunction = function(keyEvent){
        keyEvent = keyEvent ? keyEvent : window.event;
        keyEvent.which = keyEvent.which ? keyEvent.which : keyEvent.keyCode;
        keycontrol(keyEvent);
    };
    //window.document.onkeypress = clickFunction;
    window.document.onkeydown = clickFunction;
    //按键操作
    function keycontrol(obj) {
        if (obj.which == 0x0026) {
            /* 上 */
//                if(index!=0){
//                    index--;
//                    getDetail();
//                }else{
//                    index=len-1;
//                    getDetail();
//                }
        } else if (obj.which == 0x0028) {
            /* 下 */
//                if(index<len-1){
//                    index++;
//                    getDetail();
//                }else{
//                    index=0;
//                    getDetail();
//                }
        } else if (obj.which == 0x0025) {
            /* 左 */
            setPage(0);
        } else if (obj.which == 0x0027) {
            /* 右 */
            setPage(1);
        } else if (obj.which == 0x000D) {
            /* 确定 */
            window.localStorage.setItem('portalWyImgArr',imgArr.join(','));
            window.location='pics.html';
        } else if (obj.which == 113 || obj.which == 0x0008) {// 返回
//          obj.stopPropagation();
//          obj.preventDefault();
            history.go(-1);
        }
    }

    var page=0;//当前页数
    var pageH=540;//每页高度，与文字显示高度相同
    var pageMax=1;//最大页数
    var len=1;//内容列表数
    var id=GetQueryString('id');
    var imgArr=[];

    if(window.localStorage.getItem('portalWyImgIndex')){
        index=window.localStorage.getItem('portalWyImgIndex')-0;
        window.localStorage.removeItem('portalWyImgIndex');
        window.localStorage.removeItem('portalWyImgArr');
    }

    //获取详情页
    function getDetail(){
        new YAjax().request({
            url: CONFIG.HTTP + CONFIG.VILLAGE_URLS[0].getgetWanYuanContentCulars + '&objId='+id+'&pageIndex=0&pageSize=1&loginToken=' + LOGIN_TOKEN,
            method: "GET",
            success: function (data) {
                var obj = JSON.parse(data);
                console.log(obj);
                imgArr=[];
                len=obj.totalPage;
                if(obj.status=='1'){
                    if(obj.datas[0].pictures){
                        imgArr=(CONFIG.IMAGE_RESOURCES_ADDRESS+obj.datas[0].pictures).replace(/∮/g,(','+CONFIG.IMAGE_RESOURCES_ADDRESS)).split(',');
                    }else{
                        imgArr=['../images/detail/img.png'];
                    }
                    $('.title').innerHTML=(obj.datas[0].titleName.length>24?('<marquee direction="up">'+obj.datas[0].titleName+'</marquee>'):obj.datas[0].titleName);
                    $('.time').innerHTML=(obj.datas[0].postTime?obj.datas[0].postTime:obj.datas[0].createTime.slice(0,10));
                    $('.source').innerHTML=(obj.datas[0].source.length>17?('<marquee>'+obj.datas[0].source+'</marquee>'):obj.datas[0].source);
                    $('.img').src=imgArr[0];
                    document.getElementById('content').innerHTML='<p>'+obj.datas[0].content.replace(/&lt;br\/&gt;/g,'</p><p>')+'</p>';
                    pageMax=Math.ceil(document.getElementById('content').offsetHeight/pageH);
                    pageMax=(pageMax==0?1:pageMax);
                    $('.page').innerHTML=(page+1)+'/'+pageMax;
                }
            }
        })
    }
    getDetail();

    function setPage(num){//翻页，num为0表示上一页，num为1表示是下一页
        if(num==0&&page!=0){
            page--;
            document.getElementById('content').style.top=-page*pageH+'px';
        }else if(num==1&&page<pageMax-1){
            page++;
            document.getElementById('content').style.top=-page*pageH+'px';
        }
        $('.page').innerHTML=(page+1)+'/'+pageMax;
    }

    //搜索
    function $(select){
        return document.querySelector(select);
    }

    //截取传值参数
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
        var r = window.location.search.substr(1).match(reg);
        if (r!=null) return (r[2]); return null;
    }
</script>
</body>
</html>